package kr.co.bettersoft.waitnumbercustomer.adapter;

import java.util.List;

import kr.co.bettersoft.waitnumbercustomer.activity.R;
import kr.co.bettersoft.waitnumbercustomer.common.CommonConstant;
import kr.co.bettersoft.waitnumbercustomer.domain.WaitNumberEvent;

import android.content.Context;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
/**
 * 이벤트 목록을 화면에 적용할때 사용되는 아답터이다.
 * @author blue
 *
 */
public class EventListAdapter extends BaseAdapter{
	private Context context;
	private final List<WaitNumberEvent> entries;
 
	// 폰트
	private Typeface typefaceNanumGothic= null; 
	private Typeface typefaceNanumGothicBold = null;
	
	public EventListAdapter(Context context, List<WaitNumberEvent> entriesFn) {		
		this.context = context;
		this.entries = entriesFn;
		
		// 폰트 지정.
	    typefaceNanumGothic = Typeface.createFromAsset(context.getAssets(), CommonConstant.NanumGothic);  
	    typefaceNanumGothicBold = Typeface.createFromAsset(context.getAssets(), CommonConstant.NanumGothicBold);
	}
 
	public View getView(int position, View convertView, ViewGroup parent) {
 
		LayoutInflater inflater = (LayoutInflater) context
			.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
 
		View listView;
 
		if (convertView == null) {
 
			listView = new View(context);
 
			// get layout from mobile.xml
			listView = inflater.inflate(R.layout.event_list_adapter, null);
			
		} else {
			listView = (View) convertView;
		}
 
		// set value into textview
		TextView textViewSubject = (TextView) listView.findViewById(R.id.notice_list_title);
		textViewSubject.setText(((WaitNumberEvent)entries.get(position)).getSubject());
//		System.out.println("((WaitNumberEvent)entries.get(position)).getSubject():"+((WaitNumberEvent)entries.get(position)).getSubject());
		// set value into textview
//		TextView textViewCompanyName = (TextView) listView
//				.findViewById(R.id.event_list_wrapper_companyname);
//		textViewCompanyName.setText(((WaitNumberEvent)entries.get(position)).getCompanyName());
//		System.out.println("((WaitNumberEvent)entries.get(position)).getCompanyName():"+((WaitNumberEvent)entries.get(position)).getCompanyName());
		// set value into textview
		
		TextView storeNameView = (TextView) listView.findViewById(R.id.store_name_view);
		storeNameView.setText(((WaitNumberEvent)entries.get(position)).getCompanyName());		
		
		TextView textViewRegisterDate = (TextView) listView.findViewById(R.id.notice_list_register_date);
		textViewRegisterDate.setText(((WaitNumberEvent)entries.get(position)).getRegisterDate());		
//		TextView textViewContent = (TextView) listView
//		.findViewById(R.id.event_list_wrapper_content);
//		textViewContent.setText(((WaitNumberEvent)entries.get(position)).getContent());
//		// set image based on selected text
//		ImageView imageView = (ImageView) listView
//				.findViewById(R.id.event_list_wrapper_imageFile);
//		imageView.setImageBitmap(((WaitNumberEvent)entries.get(position)).getImageFile());
		
		// 폰트 적용
		textViewSubject.setTypeface(typefaceNanumGothicBold);	
		storeNameView.setTypeface(typefaceNanumGothic);	
		textViewRegisterDate.setTypeface(typefaceNanumGothic);	
		
		
		return listView;
	}
 
	@Override
	public int getCount() {
		return entries.size();
	}
 
	@Override
	public Object getItem(int position) {
		return null;
	}
 
	@Override
	public long getItemId(int position) {
		return 0;
	}
}
